Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.

Swap OpenAI Swarm ⚒️ OpenAI Agents framework (modern)#50

Merged
jhaynie merged 2 commits intomainfrom
openai-agents
Aug 19, 2025
Merged

Swap OpenAI Swarm ⚒️ OpenAI Agents framework (modern)#50
jhaynie merged 2 commits intomainfrom
openai-agents

Conversation

@jhaynie
Copy link
Copy Markdown
Member

@jhaynie jhaynie commented Aug 19, 2025

Summary by CodeRabbit

  • New Features

    • Adds a multi-agent assistant with automatic triage and routing between generalist and technical specialists.
    • Adds input-validation guardrails to block invalid queries and surface reasoning.
    • Includes a welcome message and sample prompts to help users get started.
    • Improves end-to-end request handling with enhanced logging and error responses.
  • Refactor

    • Replaces the previous Swarm-based implementation with the new OpenAI Agents framework.
  • Chores

    • Updates templates: adds an “OpenAI Agents” option and removes the deprecated “OpenAI Swarm” template.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Aug 19, 2025

Walkthrough

Replaces the Swarm-based orchestration with an OpenAI Agents multi-agent triage workflow: adds classification, general, and technical agents with an input-validation guardrail and triage routing; removes the Swarm module and template; updates python-uv templates to use the new agents module and dependencies.

Changes

Cohort / File(s) Summary
New OpenAI Agents orchestration
common/py/openai_agents.py
Adds QueryClassification model, classification_agent, general_assistant_agent, technical_agent, query_validation_guardrail, triage_agent, welcome(), and async run() that invokes Runner.run(triage_agent, ...) with logging and error handling.
Remove Swarm integration
common/py/swarm.py
Removes Swarm client, welcome(), transfer_to_specialist(), main_agent, specialist_agent, and the async run() handler; deletes Swarm-based orchestration.
Templates update
python-uv/templates.yaml
Removes "OpenAI Swarm" template and adds "OpenAI Agents" template with new dependencies (openai>=1.82.0, openai-agents-python, pydantic) and file generation from common/py/openai_agents.py.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant Req as AgentRequest
  participant Runner
  participant Triage as Triage Agent
  participant Guardrail as Validation Guardrail
  participant Classifier as Classification Agent
  participant General as General Assistant
  participant Tech as Technical Agent
  participant Resp as AgentResponse

  User->>Req: Send question
  Req->>Runner: Runner.run(triage_agent, question, context)
  Runner->>Triage: Invoke triage agent with input
  Triage->>Guardrail: query_validation_guardrail(input)
  Guardrail->>Classifier: classify input
  Classifier-->>Guardrail: QueryClassification (is_valid, category, reasoning)
  alt invalid input
    Guardrail-->>Triage: tripwire_triggered=true (guardrail output)
    Triage-->>Runner: Guardrail failure output
  else valid input
    Guardrail-->>Triage: classification info
    alt category == "technical"
      Triage->>Tech: Delegate question
      Tech-->>Triage: Response
    else
      Triage->>General: Delegate question
      General-->>Triage: Response
    end
    Triage-->>Runner: Final response
  end
  Runner-->>Resp: Return output
  Resp-->>User: Deliver response
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • rblalock

Poem

A twitch of whiskers, routes align—
I triage threads like carrot twine.
Guardrails hop, classify the lane,
General chats or tech arcane.
Agents dance in nimble streams—thump! 🐇✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 65b1e57 and 212cdf1.

📒 Files selected for processing (1)
  • common/py/openai_agents.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • common/py/openai_agents.py
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch openai-agents

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot requested a review from rblalock August 19, 2025 15:30
@jhaynie jhaynie changed the title Swap OpenAI Swarm -> OpenAI Agents framework (modern) Swap OpenAI Swarm ⚒️ OpenAI Agents framework (modern) Aug 19, 2025
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
python-uv/templates.yaml (1)

198-214: Use the official PyPI package instead of a Git dependency
The OpenAI Agents SDK is published on PyPI under the name openai-agents, and its top-level import path is agents. Please update your template to install from PyPI and drop the Git URL:

• In python-uv/templates.yaml (around lines 200–204):

   - --quiet
-    - openai>=1.82.0
-    - git+https://github.com/openai/openai-agents-python.git
+    - openai>=1.82.0
+    - openai-agents>=0.1.0   # use the PyPI package
   - pydantic

• No changes needed in common/py/openai_agents.py—it correctly does
from agents import Agent, Runner, ….

🧹 Nitpick comments (5)
common/py/openai_agents.py (4)

5-8: Restrict classification.category to a known set for deterministic routing.

Constrain category to a limited set so the triage logic can rely on it consistently.

Apply this diff:

 class QueryClassification(BaseModel):  
     is_valid: bool  
-    category: str
+    category: Literal["technical", "general", "unknown"]
     reasoning: str

Add the import near the other imports (outside this range):

from typing import Literal  # add with imports

30-38: Fail closed on guardrail errors and provide a safe fallback.

If classification fails or returns an unexpected shape, the guardrail currently raises and bubbles up. Prefer a safe fallback that triggers the tripwire instead of throwing.

Apply this diff:

 async def query_validation_guardrail(ctx, agent, input_data):  
-    result = await Runner.run(classification_agent, input_data, context=ctx)  
-    classification = result.final_output_as(QueryClassification)  
-    return GuardrailFunctionOutput(  
-        output_info=classification,  
-        tripwire_triggered=not classification.is_valid,  
-    )  
+    try:
+        result = await Runner.run(classification_agent, input_data, context=ctx)
+        classification = result.final_output_as(QueryClassification)
+        return GuardrailFunctionOutput(
+            output_info=classification,
+            tripwire_triggered=not classification.is_valid,
+        )
+    except Exception as err:
+        ctx.logger.warning("Query validation guardrail failed: %s", err)
+        fallback = QueryClassification(is_valid=False, category="unknown", reasoning="Guardrail error")
+        return GuardrailFunctionOutput(
+            output_info=fallback,
+            tripwire_triggered=True,
+        )

39-47: Make routing criteria explicit to reduce LLM ambiguity.

Tighten the triage instructions to explicitly use the guardrail’s classification for routing. This reduces prompt ambiguity and improves determinism.

Apply this diff:

 triage_agent = Agent(  
     name="Triage Agent",  
-    instructions="You determine which specialist agent to use based on the user's query. Route technical questions to the Technical Specialist and general questions to the General Assistant.",  
+    instructions=(
+        "Use the input validation guardrail classification to decide routing. "
+        "If classification.is_valid is false, do not hand off and ask the user to clarify or rephrase. "
+        "If classification.category == 'technical', hand off to the Technical Specialist. "
+        "Otherwise, hand off to the General Assistant."
+    ),
     handoffs=[general_assistant_agent, technical_agent],  
     input_guardrails=[  
         InputGuardrail(guardrail_function=query_validation_guardrail),  
     ],  
 )  

71-75: Validate empty input early for better UX.

Short-circuit on empty/whitespace-only requests and return a quick message.

Apply this diff:

-        user_question = await request.data.text()  
+        user_question = await request.data.text()
+        if not user_question or not user_question.strip():
+            return response.text("Please provide a question to process.")
python-uv/templates.yaml (1)

198-214: Pin the git dependency and ensure pydantic v2 for reproducibility.

Unpinned git installs can drift; pin to a commit SHA. Also ensure Pydantic v2 to match your BaseModel usage across templates.

Apply this diff (replace <COMMIT_SHA> with a specific commit):

     - command: uv
       args:
         - add
         - --quiet
         - openai>=1.82.0
-        - git+https://github.com/openai/openai-agents-python.git
-        - pydantic
+        - git+https://github.com/openai/openai-agents-python.git@<COMMIT_SHA>
+        - pydantic>=2.7
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 4baac9b and 65b1e57.

📒 Files selected for processing (3)
  • common/py/openai_agents.py (1 hunks)
  • common/py/swarm.py (0 hunks)
  • python-uv/templates.yaml (1 hunks)
💤 Files with no reviewable changes (1)
  • common/py/swarm.py
🔇 Additional comments (2)
common/py/openai_agents.py (1)

10-28: Nice modular agent setup and typed classification.

Good separation of concerns with a classification agent, specialists, and a triage. Using a Pydantic model for the classifier output is a solid choice.

python-uv/templates.yaml (1)

209-213: LGTM: Template wiring to the new module is correct.

The template correctly sources agent.py from common/py/openai_agents.py and keeps init.py consistent with other templates.

Comment thread common/py/openai_agents.py
Comment thread common/py/openai_agents.py
@coderabbitai coderabbitai Bot requested a review from rblalock August 19, 2025 15:43
@jhaynie jhaynie merged commit 3b9f407 into main Aug 19, 2025
3 checks passed
@jhaynie jhaynie deleted the openai-agents branch August 19, 2025 15:48
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants